package com.ugoodtech.mdcc.core.repository;

import com.ugoodtech.mdcc.core.domain.ComplaintUser;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ComplaintUserRepository extends PagingAndSortingRepository<ComplaintUser, Long>
        , QueryDslPredicateExecutor<ComplaintUser> {

    @Query(value = "SELECT * FROM complaint_user WHERE complaint_report_id=:complaintId AND user_id=:userId", nativeQuery = true)
    ComplaintUser findByComplaintId_UserId(@Param("complaintId") Long complaintId, @Param("userId") Long userId);

    @Query(value = "SELECT * FROM complaint_user WHERE complaint_report_id=:complaintId", nativeQuery = true)
    List<ComplaintUser> findByComplaintId(@Param("complaintId") Long complaintId);

    @Query(value = "SELECT * FROM complaint_user WHERE complaint_report_id in (:complaintIds) ORDER BY complaint_report_id DESC , update_time DESC LIMIT :pageNum,:pageSize ", nativeQuery = true)
    List<ComplaintUser> findByIdLimit(@Param("complaintIds") List<Long> complaintIds,
                                      @Param("pageSize") Integer pageSize,
                                      @Param("pageNum") Integer pageNum);

    @Query(value = "SELECT COUNT(*) FROM complaint_user", nativeQuery = true)
    Long getTotalNum();

}
